<?php
/**
 * 定义 Controller_BoIndex 类
 *
 * @copyright Copyright (c) 2009 iTeam
 * @author sunnycoolboy
 * @package leadtone
 * @version BoIndex 2009-04-02
 */

// {{{ includes
FLEA::loadClass('Controller_BoUploadImg');
// }}}

class Controller_BoEzpage extends Controller_BoUploadImg
{
	/**
     * 操作产品分类的对象
     *
     * @var Model_ArticleClasses
     */
    var $_modelClasses;
    

    /**
     * @var Model_Articles
     */
    var $_modelArticles;
    
    
    /**
     * @var access
     */
    var $access;
    
    /**
     * @var catid   类别ID  首页轮播图类别ID为20
     */
    var $ezCatId;
    var $dbo;
	
	/**
     * 构造函数
     *
     * @return Controller_BoIndex
     */
    function Controller_BoEzpage() {
        parent::Controller_BoUploadImg();
        $this->access = NEW_ADMIN;
        $this->ezCatId = EZ_CLASS;
        //用户角色权限控制
        if(!$this->checkDispatcher($this->access)){
            redirect(url('BoDashboard','ErrorIn'));
        }        
        $this->_modelClasses =& FLEA::getSingleton('Model_Categories');
        $this->_modelArticles =& FLEA::getSingleton('Model_Articles');
        $this->dbo = &FLEA::getDBO();
    }
    
    /**
     * 显示首页轮播图列表
     */
    function actionIndex() {
    	$catid = $this->ezCatId;
        $field = array('class_id' => $catid);        
        $table =& $this->_modelArticles->getTable();
        $pk = $table->primaryKey;
        $rowset = $table->findAll($field, 'hot DESC,dateline DESC', 10);
//        dump($this->dbo->log);
        $this->_setBack();
        $listTitle = "静态页列表";
        $listSrc = LEADTONE_DIR."/index.php?controller=Default&action=Index";
        include(TPL_DIR . '/BoEzList.php');
    } 
	/**
     * 显示产品的图片管理器
     */
    function actionPicman($errorMessage = null) {
    	$catid = $_GET['catid']?$_GET['catid']:$this->ezCatId;
    	$table =& $this->_modelArticles->getTable();
        $pk = $table->primaryKey;
    	$article = $this->_modelArticles->getArticle($_GET['id']);
		$pclass=$this->_modelClasses->getClass($catid);
        $pclasses=$this->_modelClasses->getSubClasses($pclass);
    	switch ($catid){
    		case $this->ezCatId:
    			$title = "发布静态页";
    			$ispic = true;
    		case $this->oimgCatId:
    			$title = "发布其他页轮播图";
    			$ispic = true;
    			break;
    		default:
    			$title = "发布静态页";
    			$ispic = true;
    	}
        include(TPL_DIR . '/BoEzEdit.php');
    }
    /**
     * 上传缩略图
     */
    function actionSave($errorMessage = null) {
    	$catid = $_GET['catid']?$_GET['catid']:$this->ezCatId;
    	__TRY();
        $user = $this->getUser();
		if(!$_POST['article_id'])$_POST['dateline'] = time(); 
		else $_POST['updated'] = time(); 
		$_POST['author'] = $user['ID'];
		$_POST['class_id'] = $catid;
		$_POST['content'] = $_POST['spaw1'];
        $errorMessage = $this->_uploadPicture();
        $this->_modelArticles->saveArticle($_POST);
        $ex = __CATCH();
        if (__IS_EXCEPTION($ex)) {
            //return $this->Picman($_POST, $ex->getMessage());
            var_dump($ex->getMessage());
            exit;
        }
        switch ($catid){
        	case $this->ezCatId:
        		redirect($this->_url('Index'));
        		break;
        	case $this->oimgCatId:
        		redirect($this->_url('ProList'));
        		break;        	
        	default:
        		redirect($this->_url('Index'));
        }
    }

    function actionRemove() {
        $this->_modelArticles->removeArticle($_GET['id']);
        $this->_goBack();
    } 
}